import React, { useEffect } from 'react';
import { append } from '../utils';

function main() {
  function* foo() {
    yield append('foo');
    return 100;
  }

  const f = foo();
  let result = f.next();
  append(JSON.stringify(result));

  result = f.next();
  append(JSON.stringify(result));

  append('------------------------------');

  function* bar() {
    append('1111');
    yield 100;
    append('2222');
    yield 200;
    append('3333');
    yield 300;
  }

  const generator = bar();
  append(JSON.stringify(generator.next()));
  append(JSON.stringify(generator.next()));
  append(JSON.stringify(generator.next()));
  append(JSON.stringify(generator.next()));
}

export default function GeneratorDemo() {
  useEffect(main, null);

  return (
    <div id="content">
      <p>generator</p>
    </div>
  );
}
